<template>
  <div class="comment-box">
    <el-dialog title="" :visible.sync="commentShow" @closed="closed">
      <div class="comment-fixed">
        <div class="title">课程评价</div>
        <div class="close-btn" @click="close">
          <img src="~img/close.png" alt="" />
        </div>
        <div class="row">
          <div class="label">我的评分</div>
          <div class="score">
            <div class="bg2"></div>
            <div class="bg1" :style="'width: ' + score * 20 + '%'"></div>
            <div class="touch">
              <div @click="scoreChange(1)"></div>
              <div @click="scoreChange(2)"></div>
              <div @click="scoreChange(3)"></div>
              <div @click="scoreChange(4)"></div>
              <div @click="scoreChange(5)"></div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="label">评价内容</div>
          <div class="textarea">
            <textarea placeholder="分享下课程给你带来的收获和启发吧~期待你的评价哦~" v-model="detail"></textarea>
          </div>
        </div>
        <div class="btns">
          <div class="btn" @click="confirm">确定</div>
          <div class="btn cancl" @click="close">取消</div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { commentApi } from '@/api/api'
export default {
  data() {
    return {
      id: 0,
      score: 5,
      detail: '',
      commentShow: false
    }
  },
  methods: {
    open(id) {
      this.id = id
      this.commentShow = true
    },
    close() {
      this.commentShow = false
    },
    closed() {
      this.id = 0
      this.score = 5
      this.detail = ''
    },
    scoreChange(score) {
      this.score = score
    },
    async confirm() {
      if (!this.detail) {
        this.COMMON.toast({
          msg: '请输入评价内容'
        })
      }
      const res = await commentApi({
        article_id: this.id,
        content: this.detail,
        evaluation_level: this.score
      })
      if (res.errno === 0) {
        this.$message({
          message: '评价成功',
          type: 'success'
        })
        this.$emit('reload')
        this.close()
      }
    }
  }
}
</script>

<style lang="less" scoped>
.comment-box {
  /deep/ .el-dialog {
    background-color: transparent;
    .w(1022);
    .h(663);
    box-shadow: none;
    .el-dialog__header {
      display: none;
    }
    .el-dialog__body {
      padding: 0;
    }
  }
}

.comment-fixed {
  .w(1022);
  .h(663);
  background: #fff;
  border-radius: 14px;
  position: relative;
  overflow: hidden;
  .title {
    line-height: 86px;
    padding-left: 33px;
    border-bottom: 1px solid #cecece;
    font-weight: 500;
    font-size: 26px;
    color: #000000;
  }
  .row {
    padding: 0 40px;
    margin-top: 34px;
    &:last-child {
      margin-top: 65px;
    }
    .label {
      font-size: 24px;
      color: #000000;
      line-height: 32px;
      margin-bottom: 20px;
    }
    .score {
      width: 243px;
      height: 34px;
      position: relative;
      .bg1 {
        width: 243px;
        height: 34px;
        background: url(../assets/star-1.png) no-repeat;
        background-size: auto 34px;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 1;
      }
      .bg2 {
        width: 243px;
        height: 34px;
        background: url(../assets/star-2.png) no-repeat;
        background-size: 100% 100%;
      }
      .touch {
        width: 243px;
        height: 34px;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 2;
        div {
          width: 35px;
          height: 34px;
          cursor: pointer;
          margin-right: 17px;
          float: left;
          &:last-child {
            margin-right: 0;
          }
        }
      }
    }
    .textarea {
      height: 240px;
      padding: 20px 16px;
      border-radius: 9px;
      border: 1px solid #d1d1d1;
      textarea {
        width: 100%;
        height: 200px;
        font-size: 20px;
      }
    }
  }
  .btns {
    text-align: right;
    padding-top: 34px;
    padding-right: 40px;
    .btn {
      text-align: center;
      display: inline-block;
      width: 116px;
      height: 54px;
      line-height: 52px;
      color: #fff;
      font-size: 24px;
      background: @base-color;
      border-radius: 7px;
      border: 1px solid @base-color;
      cursor: pointer;
      &.cancl {
        margin-left: 28px;
        color: @base-color;
        background: #fff;
        border: 1px solid #808080;
      }
    }
  }
  .close-btn {
    position: absolute;
    .w(26);
    .h(26);
    .right(38);
    .top(32);
    cursor: pointer;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
